<template>
	<el-dialog
		:title="title"
		:visible.sync="addComShow"
		width="50%"
		:before-close="cancel"
		:close-on-click-modal="false"
		:close-on-press-escape="false"
		top="6vh"
	>
		<el-form label-width="110px" label-position="left">
			<el-form-item label="销售机构名称" required>
				<el-input v-model.trim="managementInfo.salesOrganName" type="text" :disabled="title === '修改'" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="销售机构全称" required>
				<el-input v-model.trim="managementInfo.salesOrganFullName" type="text" :disabled="title === '修改'" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="注册地址">
				<el-input v-model.trim="managementInfo.registerAddress" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="办公地址">
				<el-input v-model.trim="managementInfo.officeAddress" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="法人">
				<el-input v-model.trim="managementInfo.corporate" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="联系人">
				<el-input v-model.trim="managementInfo.contact" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="联系电话">
				<el-input v-model.trim="managementInfo.contactPhone" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="传真">
				<el-input v-model.trim="managementInfo.fax" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="客服电话">
				<el-input v-model.trim="managementInfo.serviceTel" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="网址">
				<el-input v-model.trim="managementInfo.website" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button size="small" @click="cancel">取 消</el-button>
			<el-button size="small" type="primary" @click="addConfirm">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import { addSalesOrgListPage, editSalesOrgListPage } from '@/api/productApi/mechanism'
import { EmptyJudgment } from '@/utils/validate'
export default {
	props: {
		title: {
			type: String,
			default: ''
		},
		addComShow: {
			type: Boolean,
			default: false
		},
		comIsShow: {
			type: Function,
			default: Function
		},
		queryFundManagerList: {
			type: Function,
			default: Function
		}
	},
	data() {
		return {
			managementInfo: {},
			isDisabled: false
		}
	},
	mounted() {},
	methods: {
		cancel() {
			this.$emit('comIsShow')
			this.managementInfo = {}
		},
		// 新增或编辑
		addConfirm() {
			if (EmptyJudgment(this.managementInfo.salesOrganName) || EmptyJudgment(this.managementInfo.salesOrganFullName)) {
				this.$message({
					type: 'warning',
					message: '请填写必要参数'
				})
				return
			}
			if (this.title === '新增') {
				addSalesOrgListPage({ salesOrganInfo: this.managementInfo }).then(res => {
					if (res.msgCode === 'Y') {
						this.cancel()
						this.$emit('queryFundManagerList')
						this.$message({ message: res.msgDesc, type: 'success' })
					}
				})
			} else if (this.title === '修改') {
				editSalesOrgListPage({ salesOrganId: this.managementInfo.salesOrganId, salesOrganInfo: this.managementInfo }).then(res => {
					if (res.msgCode === 'Y') {
						this.cancel()
						this.$emit('queryFundManagerList')
						this.$message({ message: res.msgDesc, type: 'success' })
					}
				})
			}
		},
		refresh() {
			this.$forceUpdate()
		},
		edit(obj) {
			this.managementInfo = JSON.parse(obj)
		}
	}
}
</script>
<style lang="scss" scoped >
::v-deep .el-textarea__inner {
	height: 203px;
}
</style>
